//Syntax NOTE:
// match expr value; => arm: Value::String(ref s) => s: &str
// match expr value_ref => arm:  Value::String(s) =>  s: &str

#[cfg(test)]
mod test{
    #[derive(Debug)]
    enum Value {
        String(String),
        Null,
    }
    impl Value {
        fn new() -> Self {
            Value::Null
        }
    }
    #[test]
    fn match_ref_and_value(){
        fn match_value(v: Value) -> Option<String>{ //NOTE[1] return value
            let s = match v {
                Value::String(s) => Some(s),
                _ => None,
            };
            // println!("{:?}", v); //compile error: partial moved of v
            s
        }
        let mut v = Value::String("hello".to_string());
        assert_eq!("hello", match_value(v).unwrap());


        fn match_ref(v: &Value) -> Option<&str> { //NOTE[1] return ref value: &str
            let s: Option<&str> = match v {
                Value::String(s) => Some(s),
                _ => None,
            };
            println!("{:?}", v); // no moved here,
            s
        }
        v = Value::String("hello".to_string());
        assert_eq!("hello", match_ref(&v).unwrap());

        v = Value::new();
        match_ref(&v);
    }
}
